package com.wxh;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.File;

public class ExcelRead {
    @Test
    public void test1() throws Exception{
        XSSFWorkbook workbook=new XSSFWorkbook(new File("d:\\student.xlsx"));
        XSSFSheet sheet = workbook.getSheet("Sheet1");
        int firstRow = sheet.getFirstRowNum();
        int lastRow = sheet.getLastRowNum();
        for(int i=firstRow;i<=lastRow;i++){
            XSSFRow row = sheet.getRow(i);
            short firstCellNum = row.getFirstCellNum();
            short lastCellNum = row.getLastCellNum();
            for(int j=firstCellNum;j<lastCellNum;j++){
                XSSFCell cell = row.getCell(j);
                System.out.print(cell.getStringCellValue()+"\t");
            }
            System.out.println();
        }
        workbook.close();
    }
}
